package example.demo.voliate;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class DemoVoliate01 {

    public static void main(String[] args) throws InterruptedException {
        long l = System.currentTimeMillis();
        VolatileBean volatileBean = new VolatileBean();
        Thread threada = new Thread(() -> {
            for (int j = 0; j < 200000000; j++) {
                volatileBean.a++;
            }
        });

        Thread threadb = new Thread(() -> {
            for (int j = 0; j < 200000000; j++) {
                volatileBean.b++;
            }
        });
        threada.start();
        threadb.start();
        threada.join();
        threadb.join();
        //6708 5342 5655 6951 6061
        //5780 6849  5531
        System.out.println(System.currentTimeMillis()-l);
    }
}
